package com.andatsoft.laisim.receiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;

import com.andatsoft.laisim.activity.LockScreenActivity;
import com.andatsoft.laisim.utils.Common;

public class LockScreenReceiver extends BroadcastReceiver {
	@Override
	public void onReceive(Context context, Intent intent) {
		if (intent == null)
			return;
		String action = intent.getAction();
		if (action == null)
			return;
		if (action.equals(Intent.ACTION_SCREEN_ON)) {

			// check if should show lock screen
			SharedPreferences sp = context.getSharedPreferences(
					Common.SP_LOCK_SCREEN_SETTING_NAME, Context.MODE_PRIVATE);
			boolean useLaisimLock = sp.getBoolean(
					Common.SP_LOCK_SCREEN_SETTING_USE_LAISIM_LOCK, true);
			if (!useLaisimLock)
				return;
			boolean isShowLock = sp.getBoolean(
					Common.SP_LOCK_SCREEN_SETTING_SHOULD_SHOW_LOCK, false);
			if (isShowLock) {
				Intent i = new Intent(context, LockScreenActivity.class);
				i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
				context.startActivity(i);
			}

		}

	}
}
